﻿using BlazorAdmin.Generator.Models;
using System.Collections.Generic;
using System.Data.Common;

namespace BlazorAdmin.Generator.DbColumnReaders
{
    public abstract class DbColumnReader
    {
        public abstract List<Column> ReadColumns(DbConnection connection, DbProviderFactory factory, string table);

        public List<Column> SetInputTypeAuto(List<Column> cols)
        {
            cols.ForEach(column =>
            {
                if (column.PropertyType == "string")
                    column.InputType = EnumInputType.String;
                else if (column.PropertyType == "bool")
                    column.InputType = EnumInputType.Boolen;
                else if (column.PropertyType == "DateTime")
                    column.InputType = EnumInputType.DateTime;
                else if (column.PropertyType == "int" || column.PropertyType == "long" || column.PropertyType == "double" ||
                       column.PropertyType == "decimal" || column.PropertyType == "float" || column.PropertyType == "short")
                    column.InputType = EnumInputType.Number;
                else
                    column.InputType = EnumInputType.UnKnow;
            });

            return cols;
        }
    }
}
